home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / mui / MadMatrixsrc.lha / MadMatrix.src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-19  |  3.7 KB  |  149 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <proto/intuition.h>
  5. #include <proto/graphics.h>
  6. #include <proto/exec.h>
  7.  
  8.  
  9. #include <libraries/mui.h>
  10.  
  11. #include "mui.h"
  12. #include "libs.h"
  13. #include "madmatrix.h"
  14.  
  15. /*#define SOLVE*/
  16.  
  17. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  18.  
  19. int main(int argc, char **argv)
  20. {
  21.   ULONG ok;
  22.   Object *app,*win_main, *madmatrix, *restart, *shake, *taille, *groupe;
  23. #ifdef SOLVE
  24.   Object *resoud
  25. #endif
  26.  
  27.  
  28.   struct MUI_CustomClass *mcc;
  29.  
  30.   if ( ! Ouvrir_Libs() )
  31.   {
  32.     printf("Ouverture des librairies impossible\n");
  33.     return(0);
  34.   }
  35.  
  36.  
  37.  
  38.   if (!(mcc = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct Madmatrix_Data),Madmatrix_Dispatcher)))
  39.   {
  40.     printf("Cannot create custom class.\n");
  41.     return(0);
  42.   }
  43.  
  44.  
  45.  
  46.   app=ApplicationObject,
  47.     MUIA_Application_Title,     "MadMatrix",
  48.     MUIA_Application_Version,    "$VER: MadMatrix v1.2",
  49.     MUIA_Application_Copyright,   "© Olivier Croquette",
  50.     MUIA_Application_Author,    "Olivier Croquette",
  51.     MUIA_Application_Description,  "'Rotation in a matrix' Game",
  52.  
  53.     SubWindow,win_main=WindowObject,
  54.       MUIA_Window_Title,"MadMatrix",
  55.       MUIA_Window_ID , MAKE_ID('G','N','R','C'),
  56.       MUIA_CycleChain, TRUE,
  57.       WindowContents,
  58.         groupe=VGroup,
  59.           Child, TextObject,
  60.               TextFrame,
  61.               MUIA_Background, MUII_TextBack,
  62.               MUIA_Text_Contents, "I'll make you mad !",
  63.           End,
  64.           Child,
  65.             HGroup,
  66.               Child, Label("Size : "),
  67.               Child, taille=MUI_NewObject(MUIC_Slider,
  68.                                                 MUIA_Numeric_Min,3,
  69.                                                 MUIA_Numeric_Max,MADMATRIX_TAILLE_MAX,
  70.                                                 MUIA_Numeric_Format,"%1ld",
  71.                                                 MUIA_Slider_Horiz,TRUE,
  72.                                                 MUIA_Numeric_Reverse,FALSE,
  73.                                                 TAG_DONE),
  74.             End,
  75.           Child,
  76.             HGroup,
  77.               Child,restart =SimpleButton("Restart"),
  78.               Child,shake   =SimpleButton("Shake"),
  79. #ifdef SOLVE
  80.               Child,resoud   =SimpleButton("Solve"),
  81. #endif
  82.             End,
  83.  
  84.           Child, madmatrix=(Object *)NewObject(mcc->mcc_Class,NULL,TextFrame,TAG_DONE),
  85.         End,
  86.  
  87.       End,
  88.   End;
  89.  
  90.  
  91.   if(!app)
  92.   {
  93.     printf("Unable to create application.\n");
  94.     Fermer_Libs();
  95.     return(0);
  96.   }
  97.  
  98.  
  99.  
  100.   DoMethod(win_main,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  101.             app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  102.  
  103.   DoMethod(restart,MUIM_Notify,MUIA_Pressed,FALSE,madmatrix,1,MADMATRIX_RESTART);
  104.   DoMethod(shake,MUIM_Notify,MUIA_Pressed,FALSE,madmatrix,1,MADMATRIX_SHAKE);
  105. #ifdef SOLVE
  106.   DoMethod(resoud,MUIM_Notify,MUIA_Pressed,FALSE,madmatrix,1,MADMATRIX_RESOUD);
  107. #endif
  108.  
  109.   DoMethod(taille,MUIM_Notify,MUIA_Numeric_Value,MUIV_EveryTime,madmatrix,3,MUIM_Set,MADMATRIX_TAILLE,MUIV_TriggerValue);
  110.  
  111.   set(win_main,MUIA_Window_DefaultObject, (LONG)madmatrix);
  112.   set(win_main,MUIA_Window_Open,TRUE);
  113.  
  114.   get(win_main,MUIA_Window_Open,&ok);
  115.  
  116.   set(madmatrix,MADMATRIX_GROUPE,(ULONG)groupe);
  117.  
  118.   if ( argc > 1 )
  119.   {
  120.     set(taille,MUIA_Numeric_Value,atoi(argv[1]));
  121.     set(madmatrix,MADMATRIX_TAILLE,atoi(argv[1]));
  122.     DoMethod(madmatrix,MADMATRIX_RESTART);
  123.   }
  124.   else
  125.     set(taille,MUIA_Numeric_Value,MADMATRIX_TAILLE_MAX);
  126.  
  127.  
  128.   if(ok)
  129.   {
  130.  
  131.     LONG sigs=0;
  132.  
  133.     while(DoMethod(app,MUIM_Application_NewInput,&sigs)!= (unsigned int)MUIV_Application_ReturnID_Quit)
  134.     {
  135.       if(sigs)
  136.         Wait(sigs);
  137.     }
  138.   }
  139.  
  140.   MUI_DisposeObject(app);
  141.   MUI_DeleteCustomClass(mcc);
  142.  
  143.  
  144.   Fermer_Libs();
  145.  
  146.   return(0);
  147. }
  148.  
  149.